﻿using System.Collections.Generic;
using System.Domain.Entity;
using System.Domain.IRepository;
using System.Repository.Base;
using System.Repository.DataBase.Models;
using Domain.Infrastructure;
using Microsoft.EntityFrameworkCore;

namespace System.Repository
{
    /// <summary>
    ///程序日志 接口 仓库实现 
    /// </summary>	
    public class SysProgramLogRepository : RepositoryDomain<SysProgramLogEntity, Sys_ProgramLog>, ISysProgramLogRepository
    {
        public SysProgramLogRepository(IDbContextConfig config) : base(config)
        {
        }

        public override bool Update(SysProgramLogEntity entity)
        {
            Sys_ProgramLog model = GetModel(entity.Id);
            if (model == null)
                return false;
            Dbcontext.Set<Sys_ProgramLog>().Attach(model);
            Dbcontext.Entry(model).State = EntityState.Unchanged;
            AutoCopy(model, entity);
            return Dbcontext.SaveChanges() > 0;
        }

        //public override bool Delete(string key)
        //{
        //    return Delete(t => t.Id == (long)key) > 0;
        //}
        public List<SysProgramLogEntity> GetList(Pagination pagination, DateTime start, DateTime end)
        {
            var expression = ExtLinq.True<Sys_ProgramLog>();
            expression = expression.And(t => t.Date >= start).And(t => t.Date <= end);

            return GetList(expression, pagination);
        }
    }
}
